<?
//设置需要搜索的表格的前缀后缀
$table_Suffix=$sys_list_table;
$table=$table_Prefix.$table_Suffix;
//设置需要搜索的表格的前缀后缀


//设置需要搜索的表格的排序项和升降项
$sort_by = "nid";
$sort_order = "desc";
//设置需要搜索的表格的排序项和升降项
?>


<?



$trans_nid = $_REQUEST ['nid']; 
 
$result = mysql_query("SELECT * FROM $table where nid = '$trans_nid'");

while($row = mysql_fetch_array($result))
  {
  $detail_nid             =$row['nid'];
  $detail_mid             =$row['mid'];
  $detail_name            =$row['name'];
  $detail_en_name         =$row['en_name'];
  $detail_short_desc      =$row['short_desc'];
  $detail_title           =$row['title'];
  $detail_keyword         =$row['keyword'];
  $detail_description     =$row['description'];
  $detail_url             =$row['url'];
  
  $detail_model           =$row['model'];
  $detail_introduce       =$row['introduce'];
  $detail_introduce2       =$row['introduce2'];
  $detail_introduce3       =$row['introduce3'];
  $detail_detail          =$row['detail'];
  $detail_detail2          =$row['detail2'];
  $detail_detail3          =$row['detail3'];
  $detail_stock           =$row['stock'];
  $detail_price           =$row['price'];
  $detail_memberprice     =$row['memberprice'];
  $detail_discountprice   =$row['discountprice'];
  $detail_local           =$row['local'];
  $detail_listorder       =$row['listorder'];
  $detail_hotsale         =$row['hotsale'];
  $detail_discount        =$row['discount'];
  $detail_recommend       =$row['recommend'];
  $detail_soldout         =$row['soldout'];

  $detail_clickrate       =$row['clickrate'];
  $detail_onsaletime      =$row['onsaletime'];



  //关于时间的一些数据
  $detail_publish         =$row['publish'];

    if((!$row['publish'])or(strstr($row['publish'],"1970")))
    {
      $detail_publish=date("Y-m-d H:s:i");
    }
    else
    {
      $detail_publish     =$row['publish'];
    }




    if((!$row['inputtime'])or(strstr($row['inputtime'],"1970")))
  {
    $detail_inputtime=date("Y-m-d H:s:i");
  }
  else
  {
    $detail_inputtime       =$row['inputtime'];//这个是录入时间，如果为空，就变成今天
  }


    if((!$row['modifytime'])or(strstr($row['modifytime'],"1970")))
    {
      $detail_modifytime=date("Y-m-d H:s:i");
    }
    else
    {
      $detail_modifytime      =$row['modifytime'];//这个是录入时间，如果为空，就变成今天
    }





  $detail_icon            =$row['icon'];
  $detail_video            =$row['video'];
  $detail_banner          =$row['banner'];
  
  $detail_image1          =$row['image1'];
  $detail_image2          =$row['image2'];
  $detail_image3          =$row['image3'];
  $detail_image4          =$row['image4'];
  $detail_image5          =$row['image5'];
  
  $detail_image6          =$row['image6'];
  $detail_image7          =$row['image7'];
  $detail_image8          =$row['image8'];
  $detail_image9          =$row['image9'];
  $detail_image10          =$row['image10'];
  $detail_extend_img      =$row['extend_img'];
  
  
  $detail_mark=$row['mark'];
  $detail_markorder=$row['markorder'];
  
  $detail_link=$row['link'];
  $detail_storage=$row['storage'];
  
  $termorder=$row['termorder'];
  
  $detail_attachment=$row['attachment'];
  $detail_vip=$row['vip_term'];
 
  }
  


  
//设置需要搜索的表格的前缀后缀
$table_Suffix='relation';
$table=$table_Prefix.$table_Suffix;
//设置需要搜索的表格的前缀后缀


//开始读取所有的detail对term数据

//echo "当前数据nid".$trans_nid;
//echo "<br/>";

$query = mysql_query("SELECT * FROM $table where detail_nid = '$trans_nid' and belong is NULL "); 

while($row = mysql_fetch_array($query))
  {
  $relation_detail_nid[]    =$row['detail_nid'];
  $relation_term_nid[]      =$row['term_nid'];
  $relation_nid[]           =$row['nid'];
  }

$query = mysql_query("SELECT * FROM $table where detail_nid = '$trans_nid' and belong = 'brand' "); 

while($row = mysql_fetch_array($query))
  {
  $brand_detail_nid[]    =$row['detail_nid'];
  $brand_term_nid[]      =$row['term_nid'];
  $brand_nid[]           =$row['nid'];
  }
 
 
 $query = mysql_query("SELECT * FROM $table where detail_nid = '$trans_nid' and belong = 'shop' "); 

while($row = mysql_fetch_array($query))
  {
  $shop_detail_nid[]    =$row['detail_nid'];
  $shop_term_nid[]      =$row['term_nid'];
  $shop_nid[]           =$row['nid'];
  }

$query = mysql_query("SELECT * FROM ".$table_Prefix."detail_relation where goods_id = '$trans_nid'"); 

$i = 0;
while($row = mysql_fetch_assoc($query))
{
   
   $detail_relation_list_arr[] = $row['detail_id'];
   
   $brand_info = select_one_line_all_items($table_Prefix . "detail" , ' nid ='.$row['detail_id']);
   
   $detail_relation_list_json[$i]['title'] = $brand_info['name'];
   $detail_relation_list_json[$i]['value'] = $brand_info['nid'];
  
  $i++;
}

$detail_relation_list = implode("','",$detail_relation_list_arr);

$detail_relation_list = "'".$detail_relation_list."'";



$query = mysql_query("SELECT * FROM ".$table_Prefix."detail where nid in ($detail_relation_list)"); 

while($row = mysql_fetch_assoc($query))
{
   $detail_relation_detail[$row['nid']]['name'] =$row['name'];
   $detail_relation_detail[$row['nid']]['model'] =$row['model'];
   $detail_relation_detail[$row['nid']]['belong'] =$row['belong'];
}

$type_list  = select_lines_all_items($table=$table_Prefix.'plate','nid desc'," mid != 'index'" );

foreach($type_list as $key=>$val){
		$new_plate_list[$val['mid']]['name'] = $val['name'];
		$new_plate_list[$val['mid']]['mid'] = $val['mid'];
	}


$json_data = '';
foreach($detail_relation_list_arr as $key=>$value){
	
	$detail_relation[$key]['value'] = $value;
	$detail_relation[$key]['title'] = $detail_relation_detail[$value]['name'].$detail_relation_detail[$value]['model'].'['.$new_plate_list[$detail_relation_detail[$value]['belong']]['name'].']';
	
	
}

$json_data = json_encode($detail_relation);


$detail_relation_list_json = json_encode($detail_relation_list_json);



$product_attr = array();
$query = mysql_query("SELECT * FROM ".$table_Prefix."product_attr where detail_nid = $trans_nid "); 

while($row = mysql_fetch_assoc($query))
{
   $product_attr[$row['nid']] =$row;
}


//分类关联商品
$query = mysql_query("SELECT * FROM ".$table_Prefix."goods_term_relation where product_id = '$trans_nid' order by  nid asc");

$i = 0;
while($row = mysql_fetch_assoc($query))
{

  $goods_relation_list_arr[] = $row['goods_id'];

  $goods_info = select_one_line_all_items($table_Prefix . "detail" , ' nid ='.$row['goods_id']);

  $goods_relation_list_json[$i]['title'] = $goods_info['name'];
  $goods_relation_list_json[$i]['value'] = $goods_info['nid'];

  $i++;
}

//var_dump($trans_nid);
$goods_relation_list = implode("','",$goods_relation_list_arr);

$goods_relation_list = "'".$goods_relation_list."'";


$json_goods_list = '';

$goods_list = select_lines_all_items($table_Prefix . "detail", ' nid  desc ' , " belong = 'product' and publish = 1 ");

foreach($goods_list as $key=>$val){
  $new_goods_list[$key]['title'] = $val['name'];
  $new_goods_list[$key]['value'] = $val['nid'];
}

$json_goods_list = json_encode($new_goods_list);

$goods_relation_list_json = json_encode($goods_relation_list_json);


?>


